package io.gitee.twoke.generator.engine.impl.template.impl;

import io.gitee.twoke.generator.engine.impl.context.Context;
import io.gitee.twoke.generator.engine.impl.persistence.entity.TemplateGroupEntity;
import io.gitee.twoke.generator.engine.impl.template.CreateTemplateGroupBuilder;
import io.gitee.twoke.generator.engine.impl.template.TemplateGroup;

import java.util.ArrayList;
import java.util.List;

public class CreateTemplateGroupBuilderImpl implements CreateTemplateGroupBuilder {

    private TemplateServiceImpl templateService;

    private TemplateGroupEntity templateGroup;
    private List<String> templateIds;

    public CreateTemplateGroupBuilderImpl(TemplateServiceImpl templateService) {
        this(templateService,
                Context.getGenerateEngineConfiguration().getTemplateGroupEntityManager().create()
        );
    }

    public CreateTemplateGroupBuilderImpl(TemplateServiceImpl templateService,TemplateGroupEntity templateGroup) {
        this.templateService = templateService;
        this.templateGroup = templateGroup;
        this.templateIds = new ArrayList<String>();
    }

    @Override
    public CreateTemplateGroupBuilder name(String name) {
        templateGroup.setName(name);
        return this;
    }

    @Override
    public CreateTemplateGroupBuilder description(String description) {
        templateGroup.setDescription(description);
        return this;
    }

    @Override
    public CreateTemplateGroupBuilder templateId(String templateId) {
        this.templateIds.add(templateId);
        return this;
    }

    @Override
    public TemplateGroup create() {
        return this.templateService.create(this);
    }

    public TemplateGroupEntity getTemplateGroup() {
        return templateGroup;
    }

    public List<String> getTemplateIds() {
        return templateIds;
    }
}
